package com.bdqn.service.Impl;

import com.bdqn.entity.Parameters;
import com.bdqn.entity.SaleGoods;
import com.bdqn.mapper.GoodsManageMapper;
import com.bdqn.mapper.SaleGoodsManageMapper;
import com.bdqn.service.GoodsManageService;
import com.bdqn.service.SaleGoodsManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class SaleGoodsManageServiceImpl implements SaleGoodsManageService {
    @Autowired
    SaleGoodsManageMapper mapper;

    @Autowired
    GoodsManageMapper goodsManageMapper;
    @Override
    public List<SaleGoods> getSaleGoodsInfo(Parameters parameters) {
        return mapper.getSaleGoodsInfo(parameters);
    }

    @Override
    public int getCount(Parameters parameters) {
        return mapper.getCount(parameters);
    }

    @Override
    public int addSaleGoods(SaleGoods saleGoods) {
        float goodsPrice=goodsManageMapper.getPrice(saleGoods.getGoodsId());
        saleGoods.setProfit((saleGoods.getPrice()-goodsPrice)*saleGoods.getNumber());
        saleGoods.setInterest_rate((saleGoods.getPrice()-goodsPrice)/saleGoods.getPrice());
        return mapper.addSaleGoods(saleGoods);
    }
}
